/*=========================================================================
*  Copyright 2009 NCS Pte. Ltd. All Rights Reserved
*
*  This software is confidential and proprietary to NCS Pte. Ltd. You shall
*  use this software only in accordance with the terms of the license
*  agreement you entered into with NCS.  No aspect or part or all of this
*  software may be reproduced, modified or disclosed without full and
*  direct written authorisation from NCS.
*
*  NCS SUPPLIES THIS SOFTWARE ON AN AS IS BASIS. NCS MAKES NO
*  REPRESENTATIONS OR WARRANTIES, EITHER EXPRESSLY OR IMPLIEDLY, ABOUT THE
*  SUITABILITY OR NON-INFRINGEMENT OF THE SOFTWARE. NCS SHALL NOT BE LIABLE
*  FOR ANY LOSSES OR DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
*  MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*
*  Change Revision
*  -------------------------------------------------------------------------
*  May 28, 2009  yunfeng   Description
*/
package canglang.scan.core.base.converter;



import java.util.Date;
import java.util.Map;

import canglang.scan.core.base.util.DateUtil;

public class DateConverter extends ognl.DefaultTypeConverter {
    @Override
    public Object convertValue(Map context, Object value, Class toType) {
        if (toType == Date.class) {
            if(((String[])value)[0]==null||((String[])value)[0].trim().equalsIgnoreCase("")) return null;
                return DateUtil.convertParse(((String[])value)[0]);

        } else if (toType == String.class) {
            if(value==null)return "";
            return DateUtil.formatDate((Date)value);
        }
        return null;
    }
}
